//
//  Chufang_addView.m
//  TY-C
//
//  Created by xyyl on 2024/4/19.
//

#import "Chufang_addView.h"
#import "ComonFile.h"

//高80
@implementation Chufang_addView

- (instancetype)initWithFrame:(CGRect)frame {
    if(self == [super initWithFrame:frame]){
        [self initViews];
        self.userInteractionEnabled = YES;
    }
    return self;
}

- (void)initViews {
    _nameLab = [UILabel new];
    [self addSubview:_nameLab];
    _nameLab.frame = CGRectMake(0, 0, 40 * IPADSCALE, 27*IPADSCALE);
    _nameLab.text = @"治疗时间";
    _nameLab.textColor = RGBColor(102, 102, 102);
    _nameLab.font = ZYQFONT(18);
    _nameLab.textAlignment = NSTextAlignmentRight;

    _textField = [UITextField new];
    [self addSubview:_textField];
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.equalTo(_nameLab);
        make.right.equalTo(self.mas_right);
        make.width.equalTo(@(80*IPADSCALE));
    }];
    _textField.layer.cornerRadius = 2;
    _textField.layer.borderWidth = 1;
    _textField.layer.borderColor = RGBColor(102, 102, 102).CGColor;
    _textField.keyboardType = UIKeyboardTypeNumberPad;
    _textField.textAlignment = NSTextAlignmentCenter;
    _textField.textColor = [UIColor blackColor];
    
    _slider = [UISlider new];
    [self addSubview:_slider];
    [_slider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(4*IPADSCALE));
        make.centerY.equalTo(_nameLab.mas_centerY);
        make.left.equalTo(_nameLab.mas_right).offset(5);
        make.right.equalTo(_textField.mas_left).offset(-5);
    }];
    _slider.minimumValue = 0;
    _slider.maximumValue = 10;
    _slider.continuous = NO;///放开手值才确定
    _slider.minimumTrackTintColor = RGBColor(65, 185, 98);
    [_slider setValue:5];
    [_slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    _slider.thumbTintColor = RGBColor(65, 185, 98);
    
    _minLab = [UILabel new];
    [self addSubview:_minLab];
    _maxLab = [UILabel new];
    [self addSubview:_maxLab];
    
    [_minLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(10.5*IPADSCALE));
        make.width.equalTo(@50);
        make.top.equalTo(_slider.mas_bottom).offset(2);
        make.left.equalTo(_slider).offset(10);
        
    }];
    _minLab.text = @"1min";
    _minLab.textColor = [UIColor blackColor];
    _minLab.font = ZYQFONT(13);
    
    [_maxLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(10.5*IPADSCALE));
        make.width.equalTo(@50);
        make.top.equalTo(_slider.mas_bottom).offset(2);
        make.right.equalTo(_slider.mas_right).offset(-10);
        
    }];
    _maxLab.text = @"10min";
    _maxLab.textColor = [UIColor blackColor];
    _maxLab.font = ZYQFONT(13);
    _maxLab.textAlignment = NSTextAlignmentRight;
    
    _minLab.userInteractionEnabled = NO;
    _maxLab.userInteractionEnabled = NO;
    
}
-(void)sliderValueChanged:(UISlider *)paramSender{
    if (_type == 0) {
        _textField.text = [NSString stringWithFormat:@"%.f",paramSender.value];

    }else{
        _textField.text = [NSString stringWithFormat:@"%.1f",paramSender.value];

    }
}
@end
